package sample3.provider.dml;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;

/**
 * <pre>
 * ...
 * SqliteUpdateBuilder sql = new SqliteUpdateBuilder(uri);
 * sql.addContentValue("key", 0);
 * sql.addAndEquals("_id", 10);
 * int update = sql.update(getContentResolver());
 * ...
 * </pre>
 */
public class SqliteUpdateBuilder extends AbsDmlBuilder {
	private ContentValues mValues;

	public SqliteUpdateBuilder(Uri uri) {
		super(uri);
		mValues = new ContentValues();
	}

	public void addContentValue(String key, Boolean value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, Byte value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, byte[] value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, Double value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, Float value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, Integer value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, Long value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, Short value) {
		mValues.put(key, value);
	}

	public void addContentValue(String key, String value) {
		mValues.put(key, value);
	}

	public int update(ContentResolver contentResolver) {
		String where = null;
		String[] whereArgs = null;

		// WHERE ~ AND ~
		where = getWhere();
		whereArgs = getWhereArgs();

		return contentResolver.update(mUri, mValues, where, whereArgs);
	}

}
